import ResultHelper from "./utils/ResultHelper";
import ResponseHelper from "./utils/ResponseHelper";
import { apiLogger } from "../logger";


export default function (req, res) {
  const result = ResultHelper.error("服务器内部错误", 5000)

  const email = req.EMAIL || "unknown"
  const method = req.method || "unknown"
  const url = req.url || "unknown"
  const body = JSON.stringify(req.body) || "unknown"
  const query = JSON.stringify(req.query) || "unknown";
  const params = JSON.stringify(req.params) || "unknown";

  // 记录错误日志
  apiLogger.error("errorMiddleware", {
    email,
    method,
    url,
    body,
    params,
    query
  })

  // error 级别记录 服务器内部错误（5000）, debug 级别记录错误请求信息。

  ResponseHelper.send(result, res);
}
